<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>详解JDK 11中的新特性 - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-08-22 09:17">
      August 22, 2019 am
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      916 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      12
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="学习笔记-详解JDK-11中的新特性"><a href="#学习笔记-详解JDK-11中的新特性" class="headerlink" title="学习笔记 : 详解JDK 11中的新特性"></a>学习笔记 : 详解JDK 11中的新特性</h2><p><em>北京时间2018年9月26日,Oracle官方宣布 Java11 正式发布,这是 Java 大版本周期变化的第一个长期支持版本,非常值得关注. 从官网既可下载,最新发布的 Java11 将带来 ZGC, Http Client 等重要特性,一共包含17个 JEP (JDK Enhancement Proposals,既 JDK 增强方案提议), 其内容如下所示,更多详细信息请参阅 : <a href="http://openjdk.java.net/projects/jdk/11/" target="_blank" rel="noopener">http://openjdk.java.net/projects/jdk/11/</a></em></p>
<ol>
<li>181: Nest-Based Access Control (嵌套类可见性控制)</li>
<li>309: Dynamic Class-File Constants (动态文件常量)</li>
<li>315: Improve Aarch64 Intrinsics (改进Aarch64 Intrinsics)</li>
<li>318: Epsilon: A No-Op Garbage Collector (Epsilon:一个无操作的垃圾收集器)</li>
<li>320: Remove the Java EE and CORBA Modules (删除Java EE和CORBA模块)</li>
<li>321: HTTP Client (Standard) (<code>重点:标准HTTP客户端</code>)</li>
<li>323: Local-Variable Syntax for Lambda Parameters (用于Lambda参数的局部变量语法)</li>
<li>324: Key Agreement with Curve25519 and Curve448 (Curve25519和Curve448算法的密钥协议)</li>
<li>327: Unicode 10</li>
<li>328: Flight Recorder (飞行记录器)</li>
<li>329: ChaCha20 and Poly1305 Cryptographic Algorithms (haCha20和Poly1305加密算法支持)</li>
<li>330: Launch Single-File Source-Code Programs (启动单一文件的源代码程序)</li>
<li>331: Low-Overhead Heap Profiling (低开销的Heap Profiling)</li>
<li>332: Transport Layer Security (TLS) 1.3 (<code>重点:支持 TLS 1.3</code>)</li>
<li>333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental) (可伸缩低延迟垃圾收集器)</li>
<li>335: Deprecate the Nashorn JavaScript Engine (弃用Nashorn JavaScript引擎)</li>
<li>336: Deprecate the Pack200 Tools and API (弃用Pack200工具和API)</li>
</ol>
<h3 id="String-新增方法"><a href="#String-新增方法" class="headerlink" title="String 新增方法"></a>String 新增方法</h3><p><em>新增加一系列字符串处理方法,程序示例如下 :</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-meta">@Test</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">testString</span><span class="hljs-params">()</span> </span>&#123;

    <span class="hljs-comment">//判断字符串是否为空白</span>
    <span class="hljs-keyword">var</span> blank = <span class="hljs-string">" \t \n "</span>.isBlank();
    <span class="hljs-comment">//去除首尾空白</span>
    <span class="hljs-keyword">var</span> strip = <span class="hljs-string">" JavaStack "</span>.strip();
    <span class="hljs-comment">//去除尾部空格</span>
    <span class="hljs-keyword">var</span> trailing = <span class="hljs-string">"JavaStack "</span>.stripTrailing();
    <span class="hljs-comment">//去除首部空格</span>
    <span class="hljs-keyword">var</span> leading = <span class="hljs-string">" JavaStack"</span>.stripLeading();
    <span class="hljs-comment">//复制字符串</span>
    <span class="hljs-keyword">var</span> repeat = <span class="hljs-string">"JavaStack"</span>.repeat(<span class="hljs-number">3</span>);
    <span class="hljs-comment">//行数统计</span>
    <span class="hljs-keyword">var</span> count = <span class="hljs-string">"A\nB\nC"</span>.lines().count();
    <span class="hljs-comment">//输出结果</span>
    List.of(blank, strip, trailing, leading, repeat, count).forEach(System.out::println);

&#125;</code></pre></div>

<p><em>程序运行结果如下所示 :</em></p>
<div class="hljs"><pre><code class="hljs mipsasm">true
<span class="hljs-keyword">JavaStack
</span><span class="hljs-keyword">JavaStack
</span><span class="hljs-keyword">JavaStack
</span><span class="hljs-keyword">JavaStackJavaStackJavaStack
</span><span class="hljs-number">3</span></code></pre></div>


<h3 id="启动单一文件的源代码程序"><a href="#启动单一文件的源代码程序" class="headerlink" title="启动单一文件的源代码程序"></a>启动单一文件的源代码程序</h3><p><em>JDK11之前我们若运行一个 Java 源代码必须先编译,再运行,两个执行步骤. 而在 JDK11 版本中我们可以通过一个 Java 命令就直接搞定咯,如下所示 :</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-comment">//JDK11版本之前需先编译后再运行程序</span>
javac JavaStack.java
java JavaStack
<span class="hljs-comment">//JDK11版本可直接运行程序</span>
java JavaStack.java</code></pre></div>

<p><em>一个命令编译运行源代码的注意点 :</em></p>
<ul>
<li>只执行源文件中的第一个类,既第一个类必须包含主方法</li>
<li>不可以使用其它源文件中的自定义类( 本文件中的自定义类是可以使用的 )</li>
</ul>
<h3 id="优化局部变量类型推断"><a href="#优化局部变量类型推断" class="headerlink" title="优化局部变量类型推断"></a>优化局部变量类型推断</h3><p><em>在 var 上添加注解的语法格式在 JDK10 中是不能实现的,但在 JDK11 中加入了这样的语法</em></p>
<div class="hljs"><pre><code class="hljs java">Consumer&lt;String&gt; consumer = (<span class="hljs-meta">@Nonnull</span> <span class="hljs-keyword">var</span> s) -&gt; s.toUpperCase();</code></pre></div>


<h3 id="删除-Java-EE-和-CORBA-模块"><a href="#删除-Java-EE-和-CORBA-模块" class="headerlink" title="删除 Java EE 和 CORBA 模块"></a>删除 Java EE 和 CORBA 模块</h3><p><em>Java EE和 CORBA 两个模块在 JDK9 中已经标记<code>deprecated</code>,在 JDK11 中正式移除. JDK中 deprecated 的意思是在不建议使用,在未来的release版本会被删除. JavaEE由4部分组成 :</em></p>
<ul>
<li>JAX-WS (Java API for XML-Based Web Services)</li>
<li>JAXB (Java Architecture for XML Binding)</li>
<li>JAF (the JavaBeans Activation Framework)</li>
<li>Common Annotations</li>
</ul>
<p><em>这些特性和 JavaSE 关系不大,并且JavaEE被维护在 Github( <a href="https://github.com/javaee" target="_blank" rel="noopener">https://github.com/javaee</a> )中,版本同步造成维护困难. 最后,JavaEE 可以单独引用,Maven中心仓库也提供了 JavaEE( <a href="https://mvnrepository.com/artifact/javax/javaee-api" target="_blank" rel="noopener">https://mvnrepository.com/artifact/javax/javaee-api</a> ),所以没必要把JavaEE包含到JavaSE中. 而 CORBA( Common Object Request Broker Architecture,公共对象请求代理体系结构 )被标记为 Proposed Optional,既而表明将来可能会放弃对这些技术的必要支持</em></p>
<p><em>更多 JDK11 的新特性描述请参阅 : <a href="https://docs.oracle.com/en/java/javase/11/" target="_blank" rel="noopener">JDK11 官方文档</a></em></p>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/JDK/">JDK</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/08/27/%E4%BD%BF%E7%94%A8MyBatis%E5%AE%8C%E6%88%90%E9%80%9A%E7%94%A8DAO%E5%92%8C%E9%80%9A%E7%94%A8Service/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">使用MyBatis完成通用DAO和通用Service</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/08/21/JDK-10%E6%96%B0%E7%89%B9%E6%80%A7%E8%AF%A6%E8%A7%A3/">
                        <span class="hidden-mobile">详解JDK 10中的新特性</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "详解JDK 11中的新特性&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
